import axios from '../utils/index';
import { Pat, HttpResponse } from '@/typings/request';
const loginApi = {
    getPublicKey(callback: (T: any) => void) {
        axios
            .get(`/core/public-key`)
            .then(res => {
                callback(res.data);
            })
            .catch(err => {
                callback(err);
            });
    },
    login(data: Pat, callback: (T: any) => void) {
        axios
            .post(`/admin/login`, data)
            .then(res => {
                callback(res.data);
            })
            .catch(err => {
                callback(err);
            });
    },
    logOut(callback: (T: any) => void) {
        axios
            .post(`/admin/logout`, null, {
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
            })
            .then(res => {
                callback(res.data);
            })
            .catch(err => {
                callback(err);
            });
    },
    sendEmailCode(data: Pat, callback: (T: any) => void) {
        axios
            .post(`/admin/sendForgotPassWordEmail`, data)
            .then(res => {
                callback(res.data);
            })
            .catch(err => {
                callback(err);
            });
    },
    forgotPassword(data: Pat, callback: (T: any) => void) {
        axios
            .put(`/admin/forgetPassword`, data)
            .then(res => {
                callback(res.data);
            })
            .catch(err => {
                callback(err);
            });
    },
    resetPassword(data: Pat, callback: (T: any) => void) {
        axios
            .put(`/admin/forgetPassword`, data)
            .then(res => {
                callback(res.data);
            })
            .catch(err => {
                callback(err);
            });
    },
    checkEmailCode(data: Pat, callback: (T: any) => void) {
        axios
            .post(`/admin/checkSmsCode`, data)
            .then(res => {
                callback(res.data);
            })
            .catch(err => {
                callback(err);
            });
    },
};

export default loginApi;
